package com.sdp.wz.db.wz_warehouse_right.service.impl;

import com.sdp.wz.db.wz_warehouse_right.entity.WzWarehouseRight;
import com.sdp.wz.db.wz_warehouse_right.mapper.WzWarehouseRightMapper;
import com.sdp.wz.db.wz_warehouse_right.service.IWzWarehouseRightService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsp
 * @since 2024-07-29
 */
@Service
public class WzWarehouseRightServiceImpl extends ServiceImpl<WzWarehouseRightMapper, WzWarehouseRight> implements IWzWarehouseRightService {

	@Override
	public boolean isHaveRight(String empNo, String warehouseCode, String rightType) {
		boolean flag = false;
		LambdaQueryWrapper<WzWarehouseRight> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(WzWarehouseRight::getEmpNo, empNo);
		queryWrapper.eq(WzWarehouseRight::getWarehouseCode, warehouseCode);
		WzWarehouseRight wxWarehouseRight = getOne(queryWrapper,false);
		if(wxWarehouseRight==null || StringUtils.isEmpty(wxWarehouseRight.getWarehouseRight())) {
			return flag;
		}
		
		String right[] = wxWarehouseRight.getWarehouseRight().split(",");
		for(int i=0;i<right.length;i++) {
			if(rightType.equals(right[i])) {
				flag = true;
				break;
			}
		}
		return flag;
	}

	@Override
	public boolean isHaveRight(String empNo, String warehouseCode) {
		LambdaQueryWrapper<WzWarehouseRight> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(WzWarehouseRight::getEmpNo, empNo);
		queryWrapper.eq(WzWarehouseRight::getWarehouseCode, warehouseCode);
		WzWarehouseRight wxWarehouseRight = getOne(queryWrapper,false);
		if(wxWarehouseRight==null) {
			return false;
		}else {
			return true;
		}
	}

}
